package com.github.io.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.io.entity.SbApiResultExplanationData;
import com.github.io.mapper.SbApiResultExplanationDataMapper;
import com.github.io.service.ISbApiResultExplanationDataService;
import com.github.io.utils.TreeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author liry
 * @version 1.0
 * @date Created on 2022/9/15 10:35
 * Description:
 */
@Service("resultExplanationDataService")
public class SbApiResultExplanationDataServiceImpl extends ServiceImpl<SbApiResultExplanationDataMapper, SbApiResultExplanationData> implements ISbApiResultExplanationDataService {
    @Autowired
    private SbApiResultExplanationDataMapper resultExplanationDataMapper;
    
    /**
     * 接口响应字段数据说明 新增功能
     * @param resultExplanationData
     * @return
     */
    @Override
    public int saveResultExplanationData(SbApiResultExplanationData resultExplanationData) {
        return resultExplanationDataMapper.insert(resultExplanationData);
    }


    /**
     * 接口响应字段数据说明 修改功能
     * @param resultExplanationData
     * @return
     */
    @Override
    public int updateResultExp(SbApiResultExplanationData resultExplanationData) {
        return resultExplanationDataMapper.updateById(resultExplanationData);
    }

    /**
     * 接口响应字段数据说明 详情功能
     * @param apiId
     * @return
     */
    @Override
    public List<SbApiResultExplanationData> selectAllResultExpData(String apiId) {
        QueryWrapper<SbApiResultExplanationData> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("api_id", apiId);
        queryWrapper.orderByDesc("update_time");
        return resultExplanationDataMapper.selectList(queryWrapper);
    }


    /**
     * 获取详情
     * @param id
     * @return
     */
    @Override
    public SbApiResultExplanationData getResultExpInfo(String id) {
        return resultExplanationDataMapper.selectById(id);
    }


    /**
     * 构建树形数据
     * @param apiId
     * @return
     */
    @Override
    public List<SbApiResultExplanationData> selectTree(String apiId) {
        if (ObjectUtils.isEmpty(apiId)) return null;
        List<SbApiResultExplanationData> resultExplanationDataList = selectAllResultExpData(apiId);
        List<SbApiResultExplanationData> resultExplanationDataTree = TreeUtil.listToTree(resultExplanationDataList);
        return resultExplanationDataTree;
    }

}
